package com.wxr.controller;


import com.wxr.utils.SendEmailUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.mail.MessagingException;

@Controller
@ResponseBody
public class SendEmailController {

    @Autowired
    JavaMailSenderImpl javaMailSender;


    @RequestMapping("/sendSimpleEmail")
    public String sendSimpleEmail(){
        String subject = "小王，早上好";
        String content = "感谢哦！";
        String from = "1301379511@qq.com";
        String to = "1301379511@qq.com";
        SendEmailUtil.sendSimpleMail(javaMailSender,subject,content,from,to);
        return "Ok";
    }


    @RequestMapping("/sendMimeMail")
    public String sendMimeMail() throws MessagingException {
        Boolean html = true;
        String subject = "小王，晚上好";
        String content = "<p style='color:red'>小王小王努力学习！</p>";
        String from = "1301379511@qq.com";
        String to = "1301379511@qq.com";
        String attachmenName = "1.jpg";
        String path = "C:\\Users\\Administrator\\Pictures\\Camera Roll\\1.jpg";
        SendEmailUtil.sendMimeMail(javaMailSender,html,subject,content,attachmenName,path,from,to);
        return "Ok";
    }


}
